// let a: any = 1;
// a = true;
// a = {};
// a = [];
// a = function () {};
// a.push();
// a.call();

let b: unknown = 1;
b = true;
b = {};
b = [];
(b as number[]).push(111);

type Str = string;
const s: Str = "hello";

type Keys = "name" | "age"; // 字符串字面量类型
type XKeys = "sex" & Keys;

type XPerson = {
  [key in Keys]: string;
};

// type XPerson = {
//   name: string;
//   age: string;
// };

// interface YPerson {
//   [key in Keys]: string;
// }

// 声明合并，合并成一个类型
interface Person {
  name: string;
}
interface Person {
  age: number;
}

interface YPerson extends Person {
  age: number;
}

// function createArr(item: any, length: number): any[] {
//   const arr: any[] = [];
//   for (let i = 0; i < length; i++) {
//     arr.push(item);
//   }
//   return arr;
// }
// createArr(1, 10);

interface ZPerson {
  name: string;
}
// T 泛型参数
function createArr<U extends ZPerson, T = any>(item: T, length: number): T[] {
  const arr: T[] = [];
  for (let i = 0; i < length; i++) {
    arr.push(item);
  }
  return arr;
}
createArr<{ name: string; age: number }, string>("hello", 10);
// createArr<number>(1, 10);
// createArr<string>("hello", 10);
// createArr("hello", 10);

interface APerson {
  name: string;
  age: number;
  sex: string;
  weight?: number;
  height?: number;
}

// 泛型提供工具类型
type BPerson = Required<APerson>; // 必选
type CPerson = Partial<APerson>; // 可选
type DPerson = Pick<APerson, "name" | "age">; // 选中
type EPerson = Omit<APerson, "name" | "age">; // 排除
